package Cy.Servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Cy.DAO.CollectionDAO;
import Entity.Commodity;
import Entity.Users;
import Factory.CollectionFactory;
import extend.SelectCollection;

/**
 * Servlet implementation class SelectCollectionServlet
 */
@WebServlet("/selectcollection")
public class SelectCollectionServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private CollectionDAO collectionDAO = CollectionFactory.createDAO();
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		int curpage = Integer.parseInt(request.getParameter("curpage"));
		int pagesize = Integer.parseInt(request.getParameter("pagesize"));
		List<SelectCollection> list = collectionDAO.selectcollection(curpage, pagesize);
		List<Commodity> comlist = collectionDAO.selectcom();
		List<Users> userlist = collectionDAO.selectuser();
		int total = collectionDAO.countcollection();
		request.setAttribute("list",list);
		request.setAttribute("comlist", comlist);
		request.setAttribute("userlist", userlist);
		request.setAttribute("total", total);
		request.getRequestDispatcher("selectCollection.jsp?curpage="+curpage+"&pagesize=10").forward(request, response);
	}

}
